<template>
  <div>
    <el-form @submit.native.prevent :inline="true" class="demo-form-inline">
      <el-form-item label="驾校名称">
        <el-input
          @keyup.native.enter="submit"
          v-model="shool_names"
          placeholder="请输入关键字"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="schoolData.result" style="width: 100%">
      <el-table-column fixed label="驾校照片" width="150">
        <template slot-scope="scope">
          <img :src="scope.row.school_cover" width="100px" />
        </template>
      </el-table-column>
      <el-table-column prop="school_name" label="驾校名称"> </el-table-column>
      <el-table-column prop="school_phone" label="联系方式"> </el-table-column>
      <el-table-column prop="licensetype" label="驾照类型"> </el-table-column>
      <el-table-column prop="schoollabel" label="驾校标签"> </el-table-column>
      <el-table-column prop="school_address" label="地址" width="250">
      </el-table-column>
      <el-table-column prop="school_score" label="评分"> </el-table-column>
      <el-table-column label="操作" width="180px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="
              $router.push('/home/driverschool-update/' + scope.row.school_id)
            "
            >编辑</el-button
          >
          <el-button size="mini" type="danger" @click="det(scope.row)"
            >删除</el-button
          >
        </template> </el-table-column
      >>
    </el-table>
    <el-pagination
      style="margin: 10px"
      background
      :total="schoolData.total"
      :page-size="schoolData.pagesize"
      :current-page="schoolData.page"
      layout="->, total, prev, pager, next, jumper"
      @current-change="changeCurrentPage"
    ></el-pagination>
  </div>
</template>

<script>
import httpApi from "@/http";
export default {
  data() {
    return {
      shool_names: "",
      // 驾校列表数据
      schoolData: {
        page: 1,
        pagesize: 10,
        total: 0,
        result: [],
      },
    };
  },
  methods: {
    submit() {
      this.schoolData.page = 1;
      this.search();
    },
    det(school) {
      this.$confirm("是否删除该驾校信息", "提示", {
        ConfirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        httpApi.schoolApi.del({ school_id: school.school_id }).then((res) => {
          console.log(this.school_id);
          console.log("删除驾校", res);
          this.search();
          this.$message.success("删除成功");
        });
      });
    },
    search() {
      if (this.shool_names.trim()) {
        this.queryDriveschoolhBuName();
      } else {
        this.infoDriveSchool();
      }
    },
    infoDriveSchool() {
      let params = {
        page: this.schoolData.page,
        pagesize: this.schoolData.pagesize,
      };
      httpApi.schoolApi.queryall(params).then((res) => {
        console.log("加载驾校列表", res);
        this.schoolData.result = res.data.data.result;
        this.schoolData.total = res.data.data.total;
      });
    },

    queryDriveschoolhBuName() {
      let params = {
        page: this.schoolData.page,
        pagesize: this.schoolData.pagesize,
        schoolName: this.shool_names,
      };
      httpApi.schoolApi.queryByNameLike(params).then((res) => {
        console.log("模糊查询驾校", res);
        this.schoolData.result = res.data.data.result;
        this.schoolData.total = res.data.data.total;
      });
    },
    changeCurrentPage(page) {
      this.schoolData.page = page; // 修改当前页
      this.search();
    },
  },

  mounted() {
    this.infoDriveSchool();
  },
};
</script>

<style lang="scss" scoped>
</style>